package joelwilson.lucene.dto;

import static joelwilson.lucene.SystemConstants.creationTimeMapping;
import static joelwilson.lucene.SystemConstants.keyMapping;
import static joelwilson.lucene.SystemConstants.updateTimeMapping;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class GenericDTO {
	
	private static final String kind = "generic";
	
	private static final Mapping[] mappings = 
		{keyMapping,
		creationTimeMapping,
		updateTimeMapping};
	
	protected final Map<String, Object> dataMap;
	
	public GenericDTO() {
		dataMap = new HashMap<String, Object>(getMappings().length);
	}
	public GenericDTO(final Map<String, Object> data) {
		this();
		addData(data);
	}
	
	public Map<String, Object> getDataMap() {
		return dataMap;
	}
	public void addData(Map<String, Object> data) {
		dataMap.putAll(data);
	}
	public Mapping[] getMappings() {
		return mappings;
	}
	public String getKind() {
		return kind;
	}
	
	// GETTERS AND SETTERS
	public String getKey() {
		return (String)dataMap.get(keyMapping.getMapping());
	}
	public void setKey(String key) {
		dataMap.put(keyMapping.getMapping(), key);
	}
	public Date getCreationTime() {
		return (Date)dataMap.get(creationTimeMapping.getMapping());
	}
	public void setCreationTime(Date creationTime) {
		dataMap.put(creationTimeMapping.getMapping(), creationTime);
	}
	public Date getUpdateTime() {
		return (Date)dataMap.get(updateTimeMapping.getMapping());
	}
	public void setUpdateTime() {
		dataMap.put(updateTimeMapping.getMapping(), new Date());
	}
	public void setUpdateTime(Date updateTime) {
		dataMap.put(updateTimeMapping.getMapping(), updateTime);
	}
}
